package com.huawei.appgallery.netdiagnosekit.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.ui.framework.widget.BottomButton;
import com.huawei.appgallery.netdiagnosekit.ui.widget.NetDiagnoseItemView;
import java.lang.ref.WeakReference;
import o.cks;
import o.cku;
import o.cmq;
import o.cmv.c;
import o.cmv.d;
import o.dgm;
import o.emz;
import o.epq;
import o.FragmentManager;

public class DiagnoseFragment extends Fragment implements OnClickListener {
    private SparseArray<NetDiagnoseItemView> ʼ;
    private cmq ʽ;
    private TextView ˊ;
    private BottomButton ˋ;
    private TextView ˎ;
    private ScrollView ˏ;
    private LinearLayout ॱ;
    private int ॱॱ = 1;

    static class e extends Handler {
        private final WeakReference<DiagnoseFragment> ˋ;

        e(DiagnoseFragment diagnoseFragment) {
            this.ˋ = new WeakReference(diagnoseFragment);
        }

        public void handleMessage(Message message) {
            DiagnoseFragment diagnoseFragment = (DiagnoseFragment) this.ˋ.get();
            if (diagnoseFragment != null && diagnoseFragment.ॱˋ() != null) {
                diagnoseFragment.ˏ(message);
            }
        }
    }

    @Nullable
    public View ˋ(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        ViewGroup viewGroup2 = (ViewGroup) layoutInflater.inflate(o.cmv.e.ॱ, viewGroup, false);
        ˋ(viewGroup2);
        return viewGroup2;
    }

    private void ˋ(ViewGroup viewGroup) {
        if (ॱˋ() != null) {
            ॱˋ().setTitle(d.ˊॱ);
        }
        NetDiagnoseItemView netDiagnoseItemView = (NetDiagnoseItemView) viewGroup.findViewById(c.ʼ);
        netDiagnoseItemView.setText(d.ᐝ);
        NetDiagnoseItemView netDiagnoseItemView2 = (NetDiagnoseItemView) viewGroup.findViewById(c.ॱॱ);
        netDiagnoseItemView2.setText(d.ॱ);
        NetDiagnoseItemView netDiagnoseItemView3 = (NetDiagnoseItemView) viewGroup.findViewById(c.ʽ);
        netDiagnoseItemView3.setText(d.ʽ);
        NetDiagnoseItemView netDiagnoseItemView4 = (NetDiagnoseItemView) viewGroup.findViewById(c.ˎ);
        netDiagnoseItemView4.setText(d.ˋ);
        NetDiagnoseItemView netDiagnoseItemView5 = (NetDiagnoseItemView) viewGroup.findViewById(c.ˋॱ);
        netDiagnoseItemView5.setText(d.ˏॱ);
        NetDiagnoseItemView netDiagnoseItemView6 = (NetDiagnoseItemView) viewGroup.findViewById(c.ᐝ);
        NetDiagnoseItemView netDiagnoseItemView7 = (NetDiagnoseItemView) viewGroup.findViewById(c.ʻ);
        netDiagnoseItemView7.setText(d.ॱˊ);
        this.ॱ = (LinearLayout) viewGroup.findViewById(c.ˏॱ);
        this.ˏ = (ScrollView) viewGroup.findViewById(c.ॱˊ);
        this.ˊ = (TextView) viewGroup.findViewById(c.ॱˎ);
        this.ˎ = (TextView) viewGroup.findViewById(c.ʻॱ);
        this.ˎ.setText(ˎ(d.ʼ, Integer.valueOf(20), Integer.valueOf(10)));
        netDiagnoseItemView7.ˊ();
        this.ʼ = new SparseArray();
        this.ʼ.append(-101, netDiagnoseItemView);
        this.ʼ.append(-102, netDiagnoseItemView2);
        this.ʼ.append(-103, netDiagnoseItemView3);
        this.ʼ.append(-104, netDiagnoseItemView4);
        this.ʼ.append(-105, netDiagnoseItemView5);
        this.ʼ.append(-107, netDiagnoseItemView7);
        netDiagnoseItemView6.ॱ();
        this.ˋ = (BottomButton) viewGroup.findViewById(c.ˋ);
        this.ˋ.setOnClickListener(this);
    }

    private void ˋ(@StringRes int i, boolean z, int i2) {
        this.ˋ.setEnabled(z);
        this.ˋ.setText(i);
        this.ॱॱ = i2;
    }

    public void onClick(View view) {
        if (view instanceof BottomButton) {
            switch (this.ॱॱ) {
                case 1:
                    ˊʻ();
                    return;
                case 2:
                    ˊʼ();
                    return;
                case 3:
                    ʼᐝ();
                    return;
                default:
                    return;
            }
        } else if (view.getId() == c.ॱˎ) {
            ʽᐝ();
        }
    }

    private void ʽᐝ() {
        Fragment diagnoseLogFragment = new DiagnoseLogFragment();
        FragmentManager ॱᐝ = ॱᐝ();
        if (ॱᐝ != null) {
            ॱᐝ.ˊ().ॱ((Fragment) this).ˋ(c.ˊ, diagnoseLogFragment).ˏ("DiagnoseLogFragment").ˋ();
        }
    }

    private void ʽˊ() {
        final cku ˋ = cku.ˋ(null, ॱ(d.ॱॱ));
        ˋ.ॱ(-1, ॱ(d.ʻ));
        ˋ.ॱ(new cks(this) {
            final /* synthetic */ DiagnoseFragment ˋ;

            public void enableNetworking() {
                this.ˋ.ʼᐝ();
            }

            public void upgrade() {
                ˋ.dismissAllowingStateLoss();
            }

            public void ˋ() {
            }
        });
        ˋ.ˎ(ॱˊ());
    }

    private void ʼᐝ() {
        if (ॱˋ() != null) {
            if (this.ʽ != null) {
                this.ʽ.ˊ();
            }
            ॱˋ().finish();
        }
    }

    private void ˊʼ() {
        if (ॱˋ() != null) {
            emz.ˊ(ॱˊ(), epq.d.ˏ(dgm.ˎ(ॱˋ()), ॱˊ()));
        }
    }

    private void ˊʻ() {
        this.ʽ = new cmq(ॱˋ(), new e(this));
        this.ʽ.ˋ();
        ˋ(d.ˊ, false, 4);
        this.ॱॱ = 4;
        this.ॱ.setVisibility(8);
        this.ˏ.setVisibility(0);
    }

    private void ʿॱ() {
        ˋ(d.ˏ, true, 2);
        ˈॱ();
    }

    private void ˈॱ() {
        this.ˊ.setVisibility(0);
        this.ˊ.setOnClickListener(this);
        this.ˎ.setVisibility(8);
    }

    private void ˉॱ() {
        ˋ(d.ʻ, true, 3);
        ˈॱ();
    }

    private void ˏ(Message message) {
        NetDiagnoseItemView netDiagnoseItemView = (NetDiagnoseItemView) this.ʼ.get(message.what);
        if (netDiagnoseItemView != null) {
            netDiagnoseItemView.ˎ(message.arg1);
        } else if (message.what != 100) {
        } else {
            if (message.arg1 == -100) {
                ˉॱ();
            } else {
                ʿॱ();
            }
        }
    }

    public void ॱ() {
        ʽˊ();
    }

    public int ʾॱ() {
        return this.ॱॱ;
    }

    public void ॱ(boolean z) {
        super.ॱ(z);
        if (!z && ॱˋ() != null) {
            ((DiagnoseActivity) ॱˋ()).setTitle(d.ˊॱ);
        }
    }
}
